package com.jerei.store.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class TimerAspect {

    @Around("execution(* com.jerei.store.service.impl.*.*(..))")
    public Object getTime(ProceedingJoinPoint point) throws Throwable {
        System.out.println("AOP!!!");

        //记录开始时间
        long start=System.currentTimeMillis();
        //调用以下方法就相当于执行了Service中的注册或登录等其他业务方法
        //该方法执行时会抛出异常，必须抛出

        Object o=point.proceed();
        long end=System.currentTimeMillis();
        //计算耗时
        System.out.println("耗时="+(end-start)+"毫秒");
        return o;
    }
}
